#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    vector<int> inventoryManagement(vector<int>& stock, int cot) {
        quickSelect(stock, 0, stock.size() - 1, cot - 1);
        return vector<int>(stock.begin(), stock.begin() + cot);
    }
private:
    void quickSelect(vector<int>& nums, int left, int right, int k) {
        if (left >= right) return;
        int randomIndex = left + rand() % (right - left + 1);
        swap(nums[randomIndex], nums[right]);
        int pivot = nums[right];
        int i = left;
        for (int j = left; j < right; j++) {
            if (nums[j] <= pivot) {
                swap(nums[i], nums[j]);
                i++;
            }
        }
        swap(nums[i], nums[right]);
        if (k == i) {
            return;
        }
        else if (k < i) {
            quickSelect(nums, left, i - 1, k);
        }
        else {
            quickSelect(nums, i + 1, right, k);
        }
    }
};